package com.ruoyi.utils;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;

import java.util.HashMap;
import java.util.Map;

public class OfbizContextUtil {

    private OfbizContextUtil(){}


    public static Map<String, Object> buildConext(Object... objs) {
        Map<String, Object> combineResultMap = new HashMap<>();
        for (Object obj : objs) {
            String jsonStr = JSONObject.toJSONString(obj, false);
            Map<String, Object> objMap = JSONObject.parseObject(jsonStr, Map.class);
            combineResultMap.putAll(objMap);
        }
        return combineResultMap;
    }

    public static Map<String, Object> buildUserConext(Object... objs) {
        Map<String, Object> combineResultMap = new HashMap<>();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        String userJsonStr = JSONObject.toJSONString(user, false);
        Map<String, Object> userMap = JSONObject.parseObject(userJsonStr, Map.class);
        combineResultMap.putAll(userMap);
        for (Object obj : objs) {
            String jsonStr = JSONObject.toJSONString(obj, false);
            Map<String, Object> objMap = JSONObject.parseObject(jsonStr, Map.class);
            combineResultMap.putAll(objMap);
        }
        return combineResultMap;
    }

}
